﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SetPriceCalculateV1d0.Entity
{
    public class ItemSetPriceRuleSetV1d0
    {
        public string Name { get; set; }
        public List<ItemSetPriceRuleV1d0> ItemSetPriceRuleList { get; set; }
        public ItemSetPriceRuleSetV1d0()
        {
            Name = "Test";
            ItemSetPriceRuleList = new List<ItemSetPriceRuleV1d0>();
        }
        /// <summary>
        /// 将规则的主级别和子级别，放入列表（剔除999）并排序，然后拼接成级别序列字符串
        /// </summary>
        /// <param name="ruleList">规则列表</param>
        /// <returns>级别序列字符串</returns>
        public static string GetStringOfLevelSequence(List<ItemSetPriceRuleV1d0> ruleList)
        {
            List<short> levelList = new List<short>();
            foreach (var item in ruleList)
            {
                //若规则的主级别为999，则只有配菜，无主菜
                if (item.MainLevel != 999) levelList.Add(item.MainLevel);
                levelList.Add(item.SubLevel);
            }
            //排序
            levelList.Sort((x, y) => -x.CompareTo(y));
            //拼接
            StringBuilder levelSequence = new StringBuilder();
            levelList.ForEach(x => levelSequence.Append(x));
            return levelSequence.ToString();
        }
    }
    /// <summary>
    /// 菜品套餐价格规则表
    /// </summary>
    public class ItemSetPriceRuleV1d0
    {
        public string Name { get; set; }
        public short MainLevel { get; set; }
        public short SubLevel { get; set; }
        public float SubPrice { get; set; }
        public ItemSetPriceRuleV1d0(string name, short mainLevel, short subLevel,float subPrice)
        {
            Name = name;
            MainLevel = mainLevel;
            SubLevel = subLevel;
            SubPrice = subPrice;
        }
    }
    /// <summary>
    /// 菜品价格信息表
    /// </summary>
    [Serializable]
    public class ItemPriceInfoV1d0
    {
        public Guid UID { get; set; }
        public string ItemCode { get; set; }
        public short ItemLevel { get; set; }
        public float ItemPrice { get; set; }
        public ItemPriceInfoV1d0(string itemCode,short itemLevel,float itemPrice)
        {
            UID = Guid.NewGuid();
            ItemCode = itemCode;
            ItemLevel = itemLevel;
            ItemPrice = itemPrice;
        }
    }
    /// <summary>
    /// 已点单菜品的价格信息集
    /// </summary>
    [Serializable]
    public class ItemPriceInfoSetV1d0
    {
        //public Guid UID { get; set; }
        /// <summary>
        /// NonSet,Set,非套餐价格和套餐价格
        /// </summary>
        public string Type { get; set; }
        public List<ItemPriceInfoV1d0> ItemPriceInfoList { get; set; }
        public ItemPriceInfoSetV1d0()
        {
            //UID = Guid.NewGuid();
            Type = "NonSet";
            ItemPriceInfoList = new List<ItemPriceInfoV1d0>();
        }
        /// <summary>
        /// 按照级别对已点菜品进行排序，然后将排序后菜品的级别拼接成一个字符串
        /// </summary>
        /// <param name="ItemOrderedPriceInfoSet">已点菜品价格信息集</param>
        /// <returns>级别字符串</returns>
        public static string GetStringOfLevelSequence(ItemPriceInfoSetV1d0 ItemOrderedPriceInfoSet)
        {
            List<short> levelList = new List<short>();
            levelList = ItemOrderedPriceInfoSet.ItemPriceInfoList.Select(x => x.ItemLevel).ToList();
            //排序
            levelList.Sort((x, y) => -x.CompareTo(y));
            StringBuilder sb = new StringBuilder();
            levelList.ForEach(x => sb.Append(x));
            return sb.ToString();
        }
    }
}
